<html>
<head><meta charset="utf-8"><title>Help casting · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html">Help casting</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206253598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206253598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manmeet Singh <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206253598">(Aug 07 2020 at 13:00)</a>:</h4>
<p>How to convert a hir::Type to ast::Type?</p>



<a name="206254192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206254192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206254192">(Aug 07 2020 at 13:06)</a>:</h4>
<p>I don't think it's possible? One is a type as in "<code>42i32</code> is of type <code>i32</code>" while the other one is a piece of syntax, as in <code>x: &amp;[i32]</code></p>



<a name="206254647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206254647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manmeet Singh <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206254647">(Aug 07 2020 at 13:11)</a>:</h4>
<p>I am working on assist generate function. Trying to make it infer the return type. I don't know how to quote the function because make::fn_ doesn't accept a return type</p>



<a name="206254989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206254989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206254989">(Aug 07 2020 at 13:14)</a>:</h4>
<p>Ah, I'm not sure, but you might need to go through the textual representation</p>



<a name="206255024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206255024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206255024">(Aug 07 2020 at 13:14)</a>:</h4>
<p>There's <code>make::ty</code> which gives you an <code>ast::Type</code></p>



<a name="206255098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206255098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manmeet Singh <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206255098">(Aug 07 2020 at 13:15)</a>:</h4>
<p>Thanks</p>



<a name="206255192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206255192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manmeet Singh <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206255192">(Aug 07 2020 at 13:16)</a>:</h4>
<p>Also should I modify make::fn_ to take a return type</p>



<a name="206255229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206255229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manmeet Singh <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206255229">(Aug 07 2020 at 13:16)</a>:</h4>
<p>Ie. Option&lt;Type&gt;</p>



<a name="206255230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206255230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206255230">(Aug 07 2020 at 13:16)</a>:</h4>
<p>And you can pretty-print a <code>hir::Ty</code> using <code>ty.display(db)</code></p>



<a name="206255257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206255257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206255257">(Aug 07 2020 at 13:17)</a>:</h4>
<p>That sounds reasonable</p>



<a name="206256873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Help%20casting/near/206256873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Help.20casting.html#206256873">(Aug 07 2020 at 13:32)</a>:</h4>
<p>you should use <code>display_source_code</code> though, not <code>display</code>. The former is specifically for printing a valid source code representation</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>